{% extends 'base.html' %}
{% from 'pagination.html' import render_pager %}

{% block title %}借款管理{% endblock %}

{% block content %}
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">借款列表</div>
                        </div>
                        <div class="widget-body  am-fr">

                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a href="{{ url_for('.loan_add') }}" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</a>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                    <thead>
                                        <tr>
                                            <th>借款人</th>
                                            <th>手机</th>
                                            <th>金额</th>
                                            <th>还款日期</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% for loan in loans %}
                                        <tr class="gradeX">
                                            <td>{{ loan.user.name }}</td>
                                            <td>{{ loan.user.mobile }}</td>
                                            <td>{{ loan.count }}</td>
                                            <td>{{ loan.deadline.strftime("%Y-%m-%d") }}</td>
                                            <td>{% if loan.status %}已还款{% else %}待还款{% endif %}</td>
                                            <td>
                                                <div class="tpl-table-black-operation">
                                                    <a href="{{ url_for('.loan_edit', loan_id=loan.id) }}">
                                                        <i class="am-icon-pencil"></i> 编辑
                                                    </a>
                                                    <form method="post" action="{{ url_for('.loan_delete', loan_id=loan.id) }}" style="display: inline">
                                                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                                                        <button class="tpl-table-black-operation-del"
                                                           onclick="confirm('确定删除借款记录吗？')">
                                                            <i class="am-icon-trash"></i> 删除
                                                        </button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            {{ render_pager(pagination) }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}